﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.DAL;
using AnyOffice.Components;

namespace AnyOffice.Web.general.netdiskGX
{
    public partial class index : BasePage
    {
        string mangerid = "";//可读共享目录父id
        string mangertid = "";//可读共享目录类型
        string dowid = "";//下载id
        string userid = "";
        string depid = "";
        string prvid = "";
        private readonly DiskGXDao bll = new DiskGXDao();
        private readonly DiskTypeGXDao dbll = new DiskTypeGXDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!IsManger())
                {
                    Response.Write("没有可查看的公共文档柜！！");
                    Response.End();
                }
              
            }
        }

        /// <summary>
        /// 判断是否有可查看的公共文件夹
        /// </summary>
        /// <returns></returns>
        public bool IsManger()
        {
            bool istrue = false;
            //所有公共文件夹集合
            List<Model.DiskTypeGX> disktype = dbll.GetModelList(base.Conn, " DiskTypeName <> '" + Public_foldGX.DiskTypeName2 + "'");

            //

            UserCache cache = new UserCache();

            userid = base.User.Identity.Name;
            depid = cache.DeptId.ToString();
            prvid = cache.PrivId.ToString();

            foreach (Model.DiskTypeGX dt in disktype)
            {
                List<AnyOffice.Model.DiskGX> disk = bll.GetListByparentId(base.Conn, " ParentDiskID=0 and DiskTypeID=" + dt.DiskTypeID + "  order by Seq asc");
                foreach (Model.DiskGX d in disk)
                { 
                    if (Public_foldGX.IsCanRed(userid, depid, prvid, d.DiskID.ToString())) //判定是有读权限
                    {
                        mangerid += d.DiskID + ",";
                        string typeid = "," + dt.DiskTypeID + ",";
                        if (mangertid.IndexOf(typeid) == -1)
                        {
                            mangertid += "," + dt.DiskTypeID + ",";
                        }
                        istrue = true;
                    }
                    if (Public_foldGX.IsCanDownLoad(userid, depid, prvid, d.DiskID.ToString())) //判定是有下载权限
                    {
                        string did = "," + d.DiskID + ",";
                        if (dowid.IndexOf(did) == -1)
                        {
                            dowid += "," + d.DiskID + ",";//可下载网络硬盘类型
                        }
                        istrue = true;
                    }
                    else { continue; }

                }

            }
            Session["Readid"] = mangerid;
            Session["Readtid"] = mangertid;
            Session["isdow"] = dowid;
            return istrue;
        }

    }
}